import api from '../../mock/index.js'
import { getUserInfo, login } from '../../api/index.js'
	
const store = {
	state: {
		userInfo: null, // 用户信息
	},
	
	mutations: {
		updateUserInfo(state, info) {
			state.userInfo = info
		},
	},
	
	actions: {
		// 获取当前用户信息
		async getUserInfo({ commit }, params = {}) {
			let res = await api.post(getUserInfo, params)
			commit('updateUserInfo', res.data)
		},
		
		async login({ commit }, params = {}) {
			let res = await api.post(login, params)
			console.log('login-----',  res)
			uni.setStorageSync('login_token', res)
			commit('updateUserInfo', res.data)
			return res
		}
	},
	namespaced: true
}

export default store
